FileUploadManager = Ext
		.extend(
				Ext.Window,
				{
					constructor : function(a) {
						Ext.applyIf(this, a);
						this.initUIComponent();
						FileUploadManager.superclass.constructor.call(this, {
							id : "fileUploadManager",
							layout : "fit",
							title : "文件分类管理",
							iconCls : "menu-file",
							width : 720,
//							minWidth : 720,
							height : 620,
//							minHeight : 550,
							maximizable : true,
							border : false,
							modal : true,
							items : [ this.panel ],
							buttonAlign : "center",
							buttons : [ {
								text : "确定",
								iconCls : "btn-ok",
								scope : this,
								handler : this.selectRecord
							}, {
								text : "取消",
								iconCls : "btn-cancel",
								scope : this,
								handler : function(){
//									Ext.getCmp("fileUploadManager").dataView.clearSelections();
									Ext.getCmp("fileUploadManager").close();
								}
							} ]
						});
					},
					initUIComponent : function() {
						fileType = this.permitted_extensions;
//						var b = FileUploadManager.judgeImage(fileType);
						
						this.searchPanel = new Ext.FormPanel({
							region : "north",
							height : 35,
							frame : false,
							border : false,
							id : "fileSearchForm",
							layout : "hbox",
							layoutConfig : {
								padding : "5",
								align : "middle"
							},
							defaults : {
								xtype : "label",
								border : false,
								margins : {
									top : 0,
									right : 4,
									bottom : 4,
									left : 4
								}
							},
							items : [ {
								text : "文件名"
							}, {
								xtype : "textfield",
								name : "Q_fileName_S_LK"
							}, {
								text : "上传时间  从"
							}, {
								xtype : "datefield",
								name : "Q_createtime_D_GT",
								format : "Y-m-d",
								width:120
							}, {
								text : "至"
							}, {
								xtype : "datefield",
								name : "Q_createtime_D_LT",
								format : "Y-m-d",
								width:120
							},{
								xtype : "button",
								text : "查询",
								iconCls : "search",
								scope : this,
								handler : this.onSearch.createCallback(this)
							}, {
								xtype : "button",
								text : "清空",
								scope : this,
								iconCls : "reset",
								handler : FileDetailSearchReset
							} ]
						});
						
						this.treePanel = new zhixiang.ux.TreePanelEditor({
							region : "west",
							id : "FileUploadManagerMenu",
							title : "文件夹",
							collapsible : true,
							split : true,
							height : 450,
							width : 160,
							autoScroll : true,
							url : __ctxPath + "/system/getAllForder.do",
							onclick : function(f) {
								this.selectedNode = f;
								var g = f.id;
								var e = Ext.getCmp("fileUploadManagerGridPanel");
								if (e != null) {
									if (g == 0) {
										e.setTitle("所有文件");
									} else {
										e.setTitle(f.text + "-文件夹");
									}
									var d = e.getStore();
									d.proxy = new Ext.data.HttpProxy({
										url:__ctxPath+ "/system/listFileDetail.do?Q_forder.id_L_EQ="+g
									});
									d.baseParams = {
										parentId : g
									};
									d.reload();
								}
							},
							contextMenuItems : [
									{
										text : "新建文件夹",
										scope : this,
										iconCls : "btn-add",
										handler : function() {
											var e = Ext.getCmp("FileUploadManagerMenu");
											var d = e.selectedNode.id;
											var f = new ForderForm({
												forId : null,
												parentId : d,
												callback : function() {
													Ext.getCmp("FileUploadManagerMenu").root.reload();
												}
											}).show();
										}
									},
									{
										text : "修改文件夹",
										scope : this,
										iconCls : "btn-edit",
										handler : function() {
											var e = Ext.getCmp("FileUploadManagerMenu");
											var d = e.selectedNode.id;
											var f = new ForderForm({
												forId : d,
												parentId : null,
												callback : function() {
													Ext.getCmp("FileUploadManagerMenu").root
															.reload();
												}
											}).show();
										}
									},{
										text : "删除文件夹",
										scope : this,
										iconCls : "btn-delete",
										handler : function() {
											var e = Ext.getCmp("FileUploadManagerMenu");
											var d = e.selectedNode.id;
											if(d==1){
												Ext.ux.Toast.msg("操作提示", "根目录不能删除!");
												return;
											}
											Ext.Msg.confirm("删除操作", "你确定删除文件夹?", function(p) {
												if (p == "yes") {
													Ext.Ajax.request({
														url : __ctxPath + "/system/deleteForder.do?ids="+d,
														success : function(q, s) {
															var r = Ext.util.JSON.decode(q.responseText);
															if (r.success == false) {
																Ext.MessageBox.show({
																	title : "操作提示",
																	msg : r.msg,
																	buttons : Ext.MessageBox.OK,
																	icon : "ext-mb-error"
																});								
															} else {
																Ext.ux.Toast.msg("操作提示", "删除成功!");
															}
															Ext.getCmp("FileUploadManagerMenu").root.reload();
														},
														failure : function(q, r) {
														}
													});
												}
											});
										}
									} ]
						});
						var a = new Ext.Toolbar({
							height : 30,
							defaultType : "button",
							items : [ {
								text : "上传",
								iconCls : "btn-upload",
								handler : this.upLoadFile,
								scope : this
							}]
						});
						this.gridPanel = new HT.GridPanel({
							id : "fileUploadManagerGridPanel",
							title : "文件夹",
							region : "center",
							tbar : a,
							rowActions : true,
							url : __ctxPath + "/system/listFileDetail.do",
							fields : [ {
								name : "fileId",
								type : "int"
							}, {
								name : "fileName",
								mapping : "fileName"
							}, "ext", "note", "fileType", "filePath",
									"createtime", "fileSize"],
							columns : [ {
								header : "fileId",
								dataIndex : "fileId",
								hidden : true
							}, {
								header : "文件名称",
								dataIndex : "fileName"
							}, {
								header : "上传时间",
								dataIndex : "createtime",
								format : "y-m-d"
							}, {
								header : "大小",
								dataIndex : "fileSize",
								width : 60,
							}, new Ext.ux.grid.RowActions({
								header : "管理",
								width : 40,
								actions : [/* {
									iconCls : "btn-showDetail",
									qtip : "查看",
									style : "margin:0 3px 0 3px"
								},*/ {
									iconCls : "btn-downLoad",
									qtip : "下载",
									style : "margin:0 3px 0 3px"
								} ],
								listeners : {
									scope : this,
									"action" : this.onRowAction
								}
							}) ]
						});
						//文件预览
						/*this.gridPanel.addListener("rowdblclick", function(c,
								f, d) {
							c.getSelectionModel().each(function(e) {							
								FileAttachDetail.show(e.data.fileId);
							});
						});*/
						
						this.panel = new Ext.Panel({
							iconCls : "menu-find-doc",
							layout : "border",
							region : "center",
							border : false
						});
						
						this.panel.add(this.treePanel);
						this.panel.add(this.gridPanel);
						this.panel.add(this.searchPanel);
						
						this.panel.doLayout();
					},
					onSearch : function(c) {
						var a = Ext.getCmp("fileSearchForm");
						var b = Ext.getCmp("fileUploadManagerGridPanel");
						if (a.getForm().isValid()) {
							var d = b.getStore();
							d.proxy = new Ext.data.HttpProxy({
								url:__ctxPath+ "/system/listFileDetail.do"
							});
							$search({
								searchPanel : a,
								gridPanel : b
							});
						}
					},
					onRowAction : function(c, a, d, e, b) {
						switch (d) {
						case "btn-showDetail":
							this.showdetail(a.data.fileId);
							break;
						case "btn-downLoad":
							this.downLoad(a.data.fileId);
							break;
						}
					},
					showdetail : function(a) {
						FileAttachDetail.show(a);
					},
					downLoad : function(a) {
						//先判断文件是否存在
						Ext.Ajax.request({
							url : __ctxPath+ "/system/fileExistsFileDetail.do?fileId="+a,
							method : "POST",
							success : function(i,j) {
								var result = Ext.decode(i.responseText);
								if(result.success==true){
									window.location = __ctxPath+"/file-download.do?fileId="+a;
								}else{
									Ext.ux.Toast.msg("提示信息","服务器上资源不存在，请联系管理员！");
									return;
								}
							},
							failure : function(i,j) {
								Ext.ux.Toast.msg("提示信息","操作出错，请联系管理员！");
							}
						});
						
					},
					upLoadFile : function() {
						var p = Ext.getCmp("FileUploadManagerMenu").getSelectionModel().getSelectedNode();
						if (p == null||'0'==p.text||p.id =='0') {
							Ext.ux.Toast.msg("操作提示", "请先选择分类！");
							return;
						} 
						var b = this.callback;
						
						var a = new Ext.ux.UploadDialog.Dialog(
								{
									file_cat : this.file_cat,
									url : __ctxPath+"/file-upload.do?fileDetail.forder.forId="+p.id,
									scope : this,
									callback : function(d) {
										if (d != null && d.length > 0) {
											Ext.getCmp("fileUploadManagerGridPanel").getStore().reload();
											a.close();
										}
										
									}
								});
						a.show();
					},
					nodeClick : function(b) {
						if (b != null) {
							var c = "";
							c = b.id;
							var a = Ext.getCmp("fileUploadManagerGridPanel")
									.getStore();
							a.url = __ctxPath + "/system/listFileAttach.do";
							a.reload({
								params : {
									start : 0,
									limit : 20,
									type : "file",
									fileType : c
								}
							});
						}
					},
					// 选择
					selectRecord : function(){    	
						var records = Ext.getCmp("fileUploadManagerGridPanel").getSelectionModel().getSelections();
						if (records.length == 0) {
							Ext.MessageBox.show({
								title : '系统提示',
								msg : '请选择列表中的信息！',
								icon : Ext.MessageBox.INFO,
								buttons : Ext.Msg.OK
							})
							return;		
						} else if (!this.multiSel){
							if (records.length > 1) {
								Ext.MessageBox.show({
									title : '系统提示',
									msg : '只能选择一条信息！',
									icon : Ext.MessageBox.INFO,
									buttons : Ext.Msg.OK
								})
								return;		
							} 
						}		
						if (this.callback){
							this.callback(records);    		
						} 
						Ext.getCmp("fileUploadManager").close();
					}
//					imageDbClick : function(b) {
//						var a = b.dataView.getSelectedNodes();
//						if (a != "" && a != null && a != "undefined") {
//							FileUploadImageDetailForm.show(a[0].id);
//						}
//					}
				});
FileDetailSearchReset=function(){
	var a=Ext.getCmp("fileSearchForm");
	a.getForm().reset();
}